package com.mingliqiye.minecraft.enchantment.conflict.common;

public class Respose<T> {

    private int code = ExceptionCode.OK.getValue();
    private String message = "操作成功";
    private T data;
    private DateTime dateTime = DateTime.now();

    public Respose(int code, String message, T data, DateTime dateTime) {
        this.code = code;
        this.message = message;
        this.data = data;
        this.dateTime = dateTime;
    }

    public Respose(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public Respose(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public Respose(T data) {
        this.data = data;
    }

    public Respose() {}

    public static <T> Respose<T> builder() {
        return new Respose<>();
    }

    public static <T> Respose<T> builder(T data) {
        return new Respose<>().setData(data);
    }

    public static <T> Respose<T> error(Class<T> type, Integer code, String message) {
        return new Respose<T>().setCode(code).setMessage(message);
    }

    public static <T> Respose<T> error(Class<T> type, ExceptionCode code, String message) {
        return error(type, code.getValue(), message);
    }

    public String getMessage() {
        return message;
    }

    public Respose<T> setMessage(String message) {
        this.message = message;
        return this;
    }

    public int getCode() {
        return code;
    }

    public Respose<T> setCode(int code) {
        this.code = code;
        return this;
    }

    public DateTime getDateTime() {
        return dateTime;
    }

    public T getData() {
        return data;
    }

    public <TD> Respose<TD> setData(TD data) {
        return new Respose<>(code, message, data);
    }
}
